package com.jerry.shop.mapper;

import com.jerry.shop.bean.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

//这是Product操作数据库的mapper
@Mapper
public interface ProductMapper {

    @Select("select * from t_product")
    public List<Product> getProductList();

    @Select("select * from t_product where id=#{id}")
    public Product getProductById(String id);

    @Insert("insert into t_product(id, name, price, stock, description, icon, status, categoryType) values(#{id}, #{name}, #{price}, #{stock}, #{description}, #{icon}, #{status}, #{categoryType})")
    public int insertProduct(Product product);

    @Update("update t_product set name=#{name}, price=#{price}, stock=#{stock}, description=#{description}, icon=#{icon}, status=#{status}, categoryType=#{categoryType} where id=#{id}")
    public int updateProduct(Product product);

    @Delete("delete from t_product where id=#{id}")
    public int deleteProductById(Integer id);

    @Select("select * from t_product where status=#{status}")
    List<Product> getProductListByStatus(Integer status);

}
